home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS05.ADF
/
menudemo
/
cdio.c
next >
Wrap
C/C++ Source or Header
|
1986-01-15
|
4KB
|
130 lines
/*********************************************************************/
/* CDIO.C AmigaLink 1/25/86 */
/* Copyright (c) 1985 */
/* Commodore-Amiga, Inc. */
/* All rights reserved. */
/* */
/* No part of this program may be reproduced, transmitted, */
/* transcribed, stored in retrieval system, or translated */
/* into any language or computer language, in any form or */
/* by any means, electronic, mechanical, magnetic, optical, */
/* chemical, manual or otherwise, without the prior written */
/* permission of: */
/* Commodore-Amiga, Inc. */
/* 983 University Ave #D */
/* Los Gatos, CA. 95030 */
/* */
/*********************************************************************/
/*********************************************************************/
/* */
/* Program name: cdio */
/* */
/* Purpose: To provide standard console device interface routines */
/* such as Open, GetChar, PutChar, etc. */
/* */
/* Arguments: (window) - The window to associate the console */
/* device with. Used in CDOpen. */
/* (character) - The char to output. Used in CDPutChar */
/* (string) - The string to output. Used in CDPutStr */
/* */
/*********************************************************************/
#include "standard.h"
struct IOStdReq consoleIO = 0;
struct IOStdReq consoleREADIO = 0;
struct MsgPort consoleMsgPort = 0;
UBYTE consoleReadChar = 0;
int CDOpen(window)
struct Window *window;
{
int error;
/* Open the console device */
consoleIO.io_Data = (char *) window;
consoleIO.io_Length = sizeof(*window);
if ((error = OpenDevice("console.device", 0, &consoleIO, 0)) != 0)
{
return(error);
}
/* Set up the message port in the I/O request */
consoleMsgPort.mp_Node.ln_Type = NT_MSGPORT;
consoleMsgPort.mp_Flags = 0;
consoleMsgPort.mp_SigBit = AllocSignal(-1);
consoleMsgPort.mp_SigTask = (struct Task *) FindTask((char *) NULL);
AddPort(&consoleMsgPort);
consoleIO.io_Message.mn_ReplyPort = &consoleMsgPort;
/* Start reading */
consoleREADIO = consoleIO;
queue_read();
return(0);
}
CDClose()
{
RemPort(&consoleMsgPort);
CloseDevice(&consoleIO);
}
int CDMayGetChar()
{
register temp;
if ( GetMsg(&consoleMsgPort) == NULL ) return(-1);
temp = consoleReadChar;
queue_read();
return(temp);
}
queue_read()
{
consoleREADIO.io_Command = CMD_READ;
consoleREADIO.io_Data = &consoleReadChar;
consoleREADIO.io_Length = 1;
SendIO(&consoleREADIO); /* Due to bug in DoIO */
}
UBYTE CDGetChar()
{
register temp;
while (GetMsg(&consoleMsgPort) == NULL) ; /* during console IO */
temp = consoleReadChar;
queue_read();
return(temp);
}
CDPutChar(character)
char character;
{
consoleIO.io_Command = CMD_WRITE;
consoleIO.io_Data = &character;
consoleIO.io_Length = 1;
DoIO(&consoleIO);
}
CDPutStr(string)
char *string; /* NULL terminated string to output */
{
consoleIO.io_Command = CMD_WRITE;
consoleIO.io_Data = string;
consoleIO.io_Length = -1;
DoIO(&consoleIO);
}
CDPutStrL(string,length)
char *string; /* output a string of length length */
int length;
{
consoleIO.io_Command = CMD_WRITE;
consoleIO.io_Data = string;
consoleIO.io_Length = length;
DoIO(&consoleIO);
}